package com.shitu.soulemo.login;

import android.Manifest;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;

import com.shitu.base.BaseActivity;
import com.shitu.soulemo.R;
import com.shitu.soulemo.rn.RNLoginActivity;

public class AdActivity extends BaseActivity {
    private static final int CAMERA_REQUEST_CODE = 0x01;
    //    private ImageView imageView;
    private Handler handler;
    private VideoView video;
    private TextView text;
    private Runnable runnable = new Runnable() {
        @Override
        public void run() {
            RNLoginActivity.start(AdActivity.this);
        }
    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ad_activity);

//        imageView = findViewById(R.id.image);
//        imageView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                RNLoginActivity.start(AdActivity.this);
//            }
//        });
        video = findViewById(R.id.video);
        text = findViewById(R.id.text);
        String uri = "android.resource://" + getPackageName() + "/" + R.raw.ad;
        video.setMediaController(new MediaController(this));
        video.setVideoURI(Uri.parse(uri));
        text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RNLoginActivity.start(AdActivity.this);
            }
        });
    }

    @Override
    protected void onPostResume() {
        super.onPostResume();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (PackageManager.PERMISSION_GRANTED != this.checkSelfPermission(Manifest.permission.CAMERA)) {
                requestPermissions(new String[]{Manifest.permission.CAMERA}, CAMERA_REQUEST_CODE);
            }
        }
        video.start();
//        if (handler == null) {
//            handler = new Handler();
//        }
//        handler.postDelayed(runnable, 5000);
    }

    @Override
    protected void onPause() {
        super.onPause();
//        handler.removeCallbacks(runnable);
        finish();
    }
}
